//
//  MainViewController.m
//  南京大牌档
//
//  Created by student on 13-12-25.
//  Copyright (c) 2013年 无锡第三团队. All rights reserved.
//

#import "MainViewController.h"
#import "HomeViewController.h"
#import "MenuViewController.h"
#import "RestaurantViewController.h"
#import "GuestViewController.h"
#import "BaseNavigationViewController.h"

@interface MainViewController () 

@end

@implementation MainViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
	HomeViewController *homeViewController=[[HomeViewController alloc]init];
    MenuViewController *menuVC=[[MenuViewController alloc]init];
    RestaurantViewController *restaurantViewController=[[RestaurantViewController alloc]init];
    GuestViewController *guestViewController=[[GuestViewController alloc]init];
    
    UINavigationController *homeNac=[[BaseNavigationViewController alloc]initWithRootViewController:homeViewController];
    UINavigationController *menuNac=[[BaseNavigationViewController alloc]initWithRootViewController:menuVC];
    UINavigationController *restaurantNac=[[BaseNavigationViewController alloc]initWithRootViewController:restaurantViewController];
    UINavigationController *guestNac=[[BaseNavigationViewController alloc]initWithRootViewController:guestViewController];
  
   
    self.viewControllers=@[homeNac,menuNac,restaurantNac,guestNac];
    [self customTabBar];
    
}
-(void)customTabBar
{
    UIButton *homeButton=[UIButton buttonWithType:UIButtonTypeCustom];
    [homeButton setFrame:CGRectMake(WXHLApplicationBounds().origin.x, WXHLApplicationBounds().origin.y, 79, 49)];
    [homeButton setImage:[UIImage imageNamed:@"home_normal.png"] forState:UIControlStateNormal];
    [homeButton setImage:[UIImage imageNamed:@"home_selected.png"] forState:UIControlStateSelected];
    homeButton.tag=0;
    homeButton.selected=YES;
    lastButton=homeButton;
    [homeButton addTarget:self action:@selector(tapAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.tabBar addSubview:homeButton];
    
    UIButton *menuButton=[UIButton buttonWithType:UIButtonTypeCustom];
    [menuButton setFrame:CGRectMake(WXHLApplicationBounds().origin.x+81, WXHLApplicationBounds().origin.y, 79, TABBAR_HEIGHT)];
    [menuButton setImage:[UIImage imageNamed:@"menu_normal.png"] forState:UIControlStateNormal];
    [menuButton setImage:[UIImage imageNamed:@"menu_selected.png"] forState:UIControlStateSelected];
    menuButton.tag=1;
    [menuButton addTarget:self action:@selector(tapAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.tabBar addSubview:menuButton];
    
    UIButton *restaurantButton=[UIButton buttonWithType:UIButtonTypeCustom];
    [restaurantButton setFrame:CGRectMake(WXHLApplicationBounds().origin.x+161, WXHLApplicationBounds().origin.y, 79, 49)];
    [restaurantButton setImage:[UIImage imageNamed:@"restaurant_normal.png"] forState:UIControlStateNormal];
    [restaurantButton setImage:[UIImage imageNamed:@"restaurant_selected.png"] forState:UIControlStateSelected];
    restaurantButton.tag=2;
    [restaurantButton addTarget:self action:@selector(tapAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.tabBar addSubview:restaurantButton];
    
    UIButton *guestButton=[UIButton buttonWithType:UIButtonTypeCustom];
    [guestButton setFrame:CGRectMake(WXHLApplicationBounds().origin.x+241, WXHLApplicationBounds().origin.y, 79, 49)];
    [guestButton setImage:[UIImage imageNamed:@"guest_normal.png"] forState:UIControlStateNormal];
    [guestButton setImage:[UIImage imageNamed:@"guest_selected.png"] forState:UIControlStateSelected];
    guestButton.tag=3;
    [guestButton addTarget:self action:@selector(tapAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.tabBar addSubview:guestButton];
    
}
-(void)tapAction:(UIButton *)_button
{
    if (lastButton!=_button) {
        lastButton.selected=NO;
    }
    lastButton=_button;
    _button.selected=YES;
    lastButton.selected=YES;
    self.selectedIndex =_button.tag;
    
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
